package com.homegoods.designer.ui.fragments;

import android.os.Bundle;
import android.text.Html;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.homegoods.designer.R;
import com.homegoods.designer.util.GetOptionsUtil;
import com.kedll.library.fragment.KBaseFragment;
import com.kedll.library.util.StringUtil;
import com.kedll.library.util.ToastUtil;

/**
 * @author QiQi
 * @ClassName: BaseApplyDesignerFragment
 * @date 2018/10/6
 * @description
 */
public abstract class BaseApplyDesignerFragment extends KBaseFragment {

    private TextView tvArea;
    private GetOptionsUtil pvOptions;
    private EditText applyfragment_phone;
    private EditText applyfragment_mail;
    private EditText applyfragment_charge_standard;
    private EditText applyfragment_cost;
    private EditText applyfragment_past_projects;
    private EditText applyfragment_all_projects;
    private Button applyfragment_button;
    private RadioGroup rg_sex, rg_operation;
    private int mSex = 0;
    private int mOperation = 0;
    private RadioButton rb_man, rb_yes;

    @Override
    public void onDestroy() {
        super.onDestroy();
        pvOptions.onDestroy();
    }

    @Override
    protected void init() {
        super.init();
        applyfragment_phone = (EditText) findViewById(R.id.applyfragment_phone);
        applyfragment_mail = (EditText) findViewById(R.id.applyfragment_mail);
        applyfragment_charge_standard = (EditText) findViewById(R.id.applyfragment_charge_standard);
        applyfragment_cost = (EditText) findViewById(R.id.applyfragment_cost);
        applyfragment_past_projects = (EditText) findViewById(R.id.applyfragment_past_projects);
        applyfragment_all_projects = (EditText) findViewById(R.id.applyfragment_all_projects);
        applyfragment_button = (Button) findViewById(R.id.applyfragment_button);
        rb_man = (RadioButton) findViewById(R.id.rb_man);
        rb_yes = (RadioButton) findViewById(R.id.rb_yes);
        rg_sex = (RadioGroup) findViewById(R.id.rg_sex);
        rg_operation = (RadioGroup) findViewById(R.id.rg_operation);
        rg_sex.setOnCheckedChangeListener(listen);
        rg_operation.setOnCheckedChangeListener(listen2);


        tvArea = (TextView) findViewById(R.id.tv_area);
        ((TextView) findViewById(R.id.tv_label)).setText(Html.fromHtml(getString(R.string.designer_label_9)));

        pvOptions = new GetOptionsUtil();
        pvOptions.setOnCallBack(result -> tvArea.setText(result));
        pvOptions.initJsonData(getActivity());

    }

    public String getArea() {
        return tvArea.getText().toString().trim();
    }

    public String getPhone() {
        return applyfragment_phone.getText().toString().trim();
    }

    public String getMail() {
        return applyfragment_mail.getText().toString().trim();
    }

    public String getChargeStandard() {
        return applyfragment_charge_standard.getText().toString().trim();
    }

    public String getCost() {
        return applyfragment_cost.getText().toString().trim();
    }

    public String getPastProjects() {
        return applyfragment_past_projects.getText().toString().trim();
    }

    public String getAllProjects() {
        return applyfragment_all_projects.getText().toString().trim();
    }

    public Button getButton() {
        return applyfragment_button;
    }

    public int getSex() {
        return mSex;
    }

    public int getOperation() {
        return mOperation;
    }

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        tvArea.setOnClickListener(v -> {
            if (pvOptions != null) {
                pvOptions.show();
            }
        });
    }


    public boolean validateBaseEdit() {
        if (StringUtil.isEmpty(getArea())) {
            ToastUtil.showToast("请选择所在城市");
            return false;
        }
        //请输入手机号
        if (StringUtil.isEmpty(getPhone())) {
            ToastUtil.showToast(R.string.string_hint_phone);
            return false;
        }
        if (StringUtil.isEmpty(getMail())) {
            ToastUtil.showToast("请输入邮箱");
            return false;
        }
        if (StringUtil.isEmpty(getChargeStandard())) {
            ToastUtil.showToast("请输入设计收费标准");
            return false;
        }
        if (StringUtil.isEmpty(getCost())) {
            ToastUtil.showToast("请输入每平米报价");
            return false;
        }
        if (StringUtil.isEmpty(getPastProjects())) {
            ToastUtil.showToast("请输入每年大概做多少个项目");
            return false;
        }

        if (StringUtil.isEmpty(getAllProjects())) {
            ToastUtil.showToast("请输入一共做个多少项目");
            return false;
        }
        return true;
    }


    private RadioGroup.OnCheckedChangeListener listen = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int id = group.getCheckedRadioButtonId();
            if (id == R.id.rb_man) {
                mSex = "男士".equals(rb_man.getText().toString()) ? 0 : 1;
            } else {
                mSex = 1;
            }
        }
    };
    private RadioGroup.OnCheckedChangeListener listen2 = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int id = group.getCheckedRadioButtonId();
            if (id == R.id.rb_yes) {
                mOperation = "做".equals(rb_yes.getText().toString()) ? 0 : 1;
            } else {
                mOperation = 1;
            }
        }
    };


}
